package zee.com.customviewexample.activity

import android.graphics.drawable.GradientDrawable
import com.zee.extendobject.toColor
import kotlinx.android.synthetic.main.activity_shape.*
import setBackgroundEx
import setRadius
import setStroke
import setGradient
import solidColor
import zee.com.customviewexample.R

/**
 * 代码生成Shape
 * 通过代码----》设置View的背景
 */

class ZxShapeActivity : BaseActivity() {

    override fun getLayoutID(): Int {
        return R.layout.activity_shape
    }

    override fun initViews() {
        tv_view_shape_1.setBackgroundEx {

            setRadius {
                mRadius = 60.0f

            }
            setStroke {
                mWidth = 5
                setColor("#ff0000")
                setStroke(1, 2)
                setColor(R.color.menu_item_divider_color)
            }
            solidColor = "#00ff00".toColor()

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                setGradient {
                    setGradientColor("#ff0000", "#0000ff")
                    mOrientation = GradientDrawable.Orientation.LEFT_RIGHT

                }

            }
        }
        tv_view_shape_2.setBackgroundEx {
            setRadius {
                mRadius = 60.0f
            }
            setStroke {
                mWidth = 5
                setColor("#ff00ff")
            }
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                setGradient {
                    mStartColor = "#ff0000".toColor()
                    mEndColor = "#0000ff".toColor()
                    mOrientation = GradientDrawable.Orientation.TOP_BOTTOM

                }
            }
        }
        tv_view_shape_3.setBackgroundEx {
            setRadius {
                mRadius = 60.0f
            }
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
                setGradient {
                    mStartColor = "#ff0000".toColor()
                    mEndColor = "#0000ff".toColor()
                    mOrientation = GradientDrawable.Orientation.LEFT_RIGHT

                }
            }
            setStroke {
                mWidth = 5
                setColor("#0000ff")
            }
        }
        tv_view_shape_5.setBackgroundEx {
            solidColor = "#ff00ff".toColor()
            setRadius {
                mRadius = 10f
            }
            setStroke {
                setColor("#ff1976d1")
                mWidth = 10
            }
        }
        tv_view_shape_4.setBackgroundEx("#ff00ff", 10f, "#ff1976d1".toColor(), 10)
        tv_view_shape_5.setBackgroundEx(R.color.default_shadow_color, 10f, R.color.colorAccent, 10)

    }

}
